from typing import *


class Solution:

    def unequalTriplets(self, nums: List[int]) -> int:
        n = len(nums)
        ans = 0
        for i in range(n):
            for j in range(i + 1, n):
                for k in range(j + 1, n):
                    if nums[i] != nums[j] and nums[i] != nums[k] and nums[
                            j] != nums[k]:
                        ans += 1
        return ans


class Solution:

    def unequalTriplets(self, nums: List[int]) -> int:
        h = Counter(nums)
        p, n, ans = 0, len(nums), 0
        for k, v in h.items():
            ans += p * v * (n - p - v)
            p += v
        return ans


class Solution:

    def unequalTriplets(self, nums: List[int]) -> int:
        l, r, ans, n = 0, 0, 0, len(nums)
        nums.sort()
        while r < n:
            l = r
            while r < n and nums[r] == nums[l]:
                r += 1
            ans += (r - l) * l * (n - r)
        return ans